package app.sys.service;

import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import app.sys.data.entity.BusFile;
import app.sys.data.form.BusFileForm;
import app.sys.mapper.BusFileMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BusFileService extends ServiceImpl<BusFileMapper, BusFile> {
    public void saveBusFile(BusFileForm form) {
        List<BusFile> resBusFiles = new ArrayList<>();
        for (String fileId : form.getFileIdList()) {
            BusFile bf = new BusFile();
            if (StringUtils.isNotEmpty(bf.getFileId()) && StringUtils.isNotEmpty(bf.getBusId())) {
                bf.setFileId(fileId);
                bf.setBusId(form.getBusId());
                bf.setBusType(form.getBusType());
                bf.setBusId(form.getBusId());
                resBusFiles.add(bf);
            }
        }
        if (!CollectionUtils.isEmpty(resBusFiles)) {
            saveBatch(resBusFiles);
        }
    }

}
